package fragment;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lanou.horo.myapplication.R;

import activity.MainActivity;
import application.BasisApplication;
import de.greenrobot.event.EventBus;
import tools.UISwitchButton;
import utils.adapter.CollectionAdpter;

/**
 * Created by dllo on 15/12/4.
 */
public class SetFragment extends AbsBaseFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    private MainActivity mainActivity;
    private RelativeLayout setAlartColck,closeByTime,voice;
    private TextView title;
    private UISwitchButton switchbtn;
    private ImageView goback;
    private Button exit;

    @Override
    protected int getLayoutView() {
        return R.layout.fragment_set;
    }
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (activity instanceof MainActivity) {
            mainActivity = (MainActivity) activity;
        }
    }

    @Override
    protected void initView() {
        setAlartColck = findView(R.id.setAlartColck);
        closeByTime = findView(R.id.closeByTime);
        voice = findView(R.id.voice);
        switchbtn = findView(R.id.switchbtn);
        title = findView(R.id.titleForAllTv);
        title.setText("设置");
        switchbtn.setOnCheckedChangeListener(this);
        goback = findView(R.id.titleForAllBack);
        goback.setOnClickListener(this);
        exit = findView(R.id.exit);
        exit.setOnClickListener(this);

    }

    @Override
    protected void initData() {
        setAlartColck.setOnClickListener(this);
        closeByTime.setOnClickListener(this);
        voice.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.setAlartColck://设置闹钟

                break;
            case R.id.closeByTime://定时关闭
                mainActivity.showSleepDialog();
                break;
            case R.id.titleForAllBack://返回
               goBack();
                break;
            case R.id.exit:
                new AlertDialog.Builder(getContext())
                        .setTitle("退出")
                        .setMessage("确定要退出吗")
                        .setNegativeButton("在听会儿", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        })
                        .setPositiveButton("退出", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                BasisApplication.setUser(null);
                                EventBus.getDefault().post(false);
                                BasisApplication.setIsLogin(false);
                                goBack();

                            }
                        }).create().show();

                break;


        }

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.switchbtn://如果选中
                if (isChecked = true) {

                }
                else {

                }
                break;
        }
    }
}
